#!/bin/bash
# 启动 Streamlit Dashboard

# 脚本所在目录
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd "$SCRIPT_DIR"

echo "======================================"
echo "启动 SkyWalking 数据导出与分析平台"
echo "======================================"
echo ""

# 检查环境
if ! command -v streamlit &> /dev/null; then
    echo "❌ 错误: 找不到 streamlit 命令"
    echo "请先安装依赖: pip install -r requirements.txt"
    exit 1
fi

# 检查数据库
if [ ! -f "data/skywalking_data.db" ]; then
    echo "⚠️  警告: 数据库文件不存在 (data/skywalking_data.db)"
    echo "请先启动数据采集服务: python3 collector_service.py"
    echo ""
fi

# 设置 Python 路径
export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH"

# 启动 Streamlit
echo "🚀 启动 Dashboard..."
echo ""
echo "访问地址: http://localhost:8501"
echo "按 Ctrl+C 停止服务"
echo ""

streamlit run streamlit_dashboard.py --server.port 8501

